package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TbAlertLog;
import com.ruoyi.system.service.ITbAlertLogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 告警日志表Controller
 * 
 * @author ruoyi
 * @date 2025-02-17
 */
@RestController
@RequestMapping("/system/log")
public class TbAlertLogController extends BaseController
{
    @Autowired
    private ITbAlertLogService tbAlertLogService;

    /**
     * 查询告警日志表列表
     */
    @PreAuthorize("@ss.hasPermi('system:log:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbAlertLog tbAlertLog)
    {
        startPage();
        List<TbAlertLog> list = tbAlertLogService.selectTbAlertLogList(tbAlertLog);
        return getDataTable(list);
    }

    /**
     * 导出告警日志表列表
     */
    @PreAuthorize("@ss.hasPermi('system:log:export')")
    @Log(title = "告警日志表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbAlertLog tbAlertLog)
    {
        List<TbAlertLog> list = tbAlertLogService.selectTbAlertLogList(tbAlertLog);
        ExcelUtil<TbAlertLog> util = new ExcelUtil<TbAlertLog>(TbAlertLog.class);
        util.exportExcel(response, list, "告警日志表数据");
    }

    /**
     * 获取告警日志表详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:log:query')")
    @GetMapping(value = "/{alertId}")
    public AjaxResult getInfo(@PathVariable("alertId") String alertId)
    {
        return success(tbAlertLogService.selectTbAlertLogByAlertId(alertId));
    }

    /**
     * 新增告警日志表
     */
    @PreAuthorize("@ss.hasPermi('system:log:add')")
    @Log(title = "告警日志表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbAlertLog tbAlertLog)
    {
        return toAjax(tbAlertLogService.insertTbAlertLog(tbAlertLog));
    }

    /**
     * 修改告警日志表
     */
    @PreAuthorize("@ss.hasPermi('system:log:edit')")
    @Log(title = "告警日志表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbAlertLog tbAlertLog)
    {
        return toAjax(tbAlertLogService.updateTbAlertLog(tbAlertLog));
    }

    /**
     * 删除告警日志表
     */
    @PreAuthorize("@ss.hasPermi('system:log:remove')")
    @Log(title = "告警日志表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{alertIds}")
    public AjaxResult remove(@PathVariable String[] alertIds)
    {
        return toAjax(tbAlertLogService.deleteTbAlertLogByAlertIds(alertIds));
    }
}
